using Assets.Scripts.Controllers;
using PrimeTween;
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace Assets.Scripts.UI
{
    internal class DaySummary : MonoBehaviour
    {
        [SerializeField] private TMP_Text _totalIncomeText;
        [SerializeField] private TMP_Text _totalTipsText;
        [SerializeField] private TMP_Text _happyChildsText;

        [SerializeField] private Transform[] _punchObjects;
        [SerializeField] private Button _submitButton;

        private void OnEnable()
        {
            SoundsController.Instance.Play(Common.SoundId.Victory);

            _totalIncomeText.text = $"${StatsController.Instance.Income.ToString("N0")}";
            _totalTipsText.text = $"${StatsController.Instance.Tips.ToString("N0")}";
            _happyChildsText.text = $"{StatsController.Instance.HappyChilds}";

            for (var i = 0; i < _punchObjects.Length; i++)
            {
                Tween.PunchScale(_punchObjects[i], Vector3.one * .5f, .3f, startDelay: i * .2f);
            }

            _submitButton.transform.localScale = Vector3.zero;
            StartCoroutine(ShowSubmitButton());
        }

        private IEnumerator ShowSubmitButton()
        {
            yield return new WaitForSeconds(_punchObjects.Length * .2f + .2f);
            _submitButton.transform.localScale = Vector3.one;
            Tween.PunchScale(_submitButton.transform, Vector3.one * .5f, .3f);
        }
    }
}
